package com.yq.ylmall.product.controller.admin;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yq.ylmall.dto.product.ProductCheckDto;
import com.yq.ylmall.dto.product.ProductDto;
import com.yq.ylmall.dto.product.ProductQueryDto;
import com.yq.ylmall.dto.product.ProductSaleDto;
import com.yq.ylmall.product.service.IProductService;
import com.yq.ylmall.result.Result;
import com.yq.ylmall.result.ResultCode;
import com.yq.ylmall.vo.product.ProductInfoVo;
import com.yq.ylmall.vo.product.ProductPageVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 商品 后台前端控制器
 * </p>
 *
 * @author yzk789
 * @since 2024-05-30
 */
@RestController
@Api(tags = "商品管理接口")
@RequiredArgsConstructor
@RequestMapping("/admin/product")
public class ProductAdminController {

    private final IProductService productService;

    @ApiOperation(value = "分页条件查询商品")
    @PostMapping("/page")
    public Result<IPage<ProductPageVo>> selectProductPage(@RequestBody ProductQueryDto dto) {
        return Result.ok(productService.queryProduct(dto));
    }

    @ApiOperation(value = "根据ID查询商品所有信息")
    @GetMapping("/get/{id}")
    public Result<ProductInfoVo> getProductInfoById(@PathVariable Long id) {
        return Result.ok(productService.getProductInfoById(id));
    }

    @ApiOperation(value = "商品操作：有ID更新，无ID新增")
    @PostMapping("/operate")
    public Result<Object> operateProduct(@RequestBody ProductDto dto) {
        productService.operateProduct(dto);
        return Result.ok(ResultCode.SAVE_SUCCESS);
    }

    @ApiOperation(value = "删除商品")
    @PostMapping("/remove/{id}")
    public Result<Object> removeProduct(@PathVariable Long id) {
        productService.removeProduct(id);
        return Result.ok(ResultCode.DELETE_SUCCESS);
    }

    @ApiOperation(value = "审核商品")
    @PostMapping("/check")
    public Result<Object> checkProduct(@RequestBody ProductCheckDto dto) {
        productService.checkProduct(dto);
        return Result.ok(ResultCode.CHECK_SUCCESS);
    }

    @ApiOperation(value = "商品上下架")
    @PostMapping("/sale")
    public Result<Object> sale(@RequestBody ProductSaleDto dto) {
        productService.onSale(dto);
        return Result.ok(ResultCode.OPERATE_SUCCESS);
    }

}
